package com.lse_from.utils

/**
 * 数据返回
 *
 * @author 祁雪
 */
class ResponseResult {

    var code: Int = 200

    var msg: String = "请求成功"

    var data: Any? = null

    constructor()

    constructor(code: Int, msg: String, data: Any?) {
        this.code = code
        this.msg = msg
        this.data = data
    }

    constructor(code: Int, msg: String) {
        ResponseResult(code, msg, null)
    }

    companion object {

        private val sucCode = 200

        private val errCode = 500;

        fun suc(msg: String?, data: Any?): ResponseResult {
            return ResponseResult(sucCode, if (msg.isNullOrBlank()) "" else msg, data)
        }

        fun sucData(data: Any): ResponseResult {
            return suc("Request SUC", data)
        }

        fun err(msg: String?, data: Any?): ResponseResult {
            return ResponseResult(errCode, if (msg.isNullOrBlank()) "" else msg, data)
        }

        fun result(code: Int, msg: String, data: Any?): ResponseResult {
            return ResponseResult(code, msg, data)
        }

        fun custom(flag: Boolean, msg: String): ResponseResult {
            return custom(flag, msg, null)
        }

        fun custom(flag: Boolean, msg: String, data: Any?): ResponseResult {
            if (flag) {
                return suc(msg, data)
            } else {
                return err(msg, data)
            }
        }

    }

}